$(document).ready(function(){
	cw.common.setStyle();
	//$('#subImg').bind('click',subButton);
	//cw.common.getUserSession(loadRoleTree,true);
	
	//初始化年份
	var myDate=new Date();
	//alert(myDate.getFullYear().toString()+"-"+myDate.getMonth().toString()+"-"+myDate.getDate().toString());
	//alert(myDate.getMonth().toString());
	var temp_mon = myDate.getMonth().toString();
	var mon_int = parseInt(temp_mon)+1;
	mm(myDate.getFullYear().toString()+"-"+mon_int+"-"+myDate.getDate().toString());
	
	getReportList();
	
})
var ROWS_COUNT = 0;
function getReportList(){
	ROWS_COUNT = 0;
	var url = cw.common.path + '/json?action=QUERY_T_FIXED_ASSETSBY_PAGER_FOR_REPORT_ACTION';
	url += "&CREATE_DATE_BEGIN="+$('#CREATE_DATE_BEGIN').val()+"&CREATE_DATE_END="+$('#CREATE_DATE_END').val()+"&IS_VALID=1";
	var xmlname = "T_FIXED_ASSETS";
	var pagePanel='#pager';
	var result='#list';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	cw.common.changePage(url,pageSize,xmlname,result,fn_getUserList,pagePanel,defaultHtml);
}
function fn_getUserList(obj,result,i){
	ROWS_COUNT = 1;
	var str = "<li>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.BARCODE+"</em>";
	str += "<em style='width: 9%; text-align: center;''>"+obj.FIXED_ASSETS_NAME+"</em>";
	str += "<em style='width: 9%; text-align: center;''>"+obj.WITH_MANANGER+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.STORED_IN+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+cw.common.toChar(obj.STOCK_DATE,'yyyy-mm-dd')+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.USE_YEAR+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.WARRANTY+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.SPECIFICATION+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.SUPPLIERS_NO+"</em>";
	str += "<em style='width: 9%; text-align: center;'>"+obj.FACTORY_NO+"</em>";
	str += "</em></li>";
	$(result).append(str);
}

//删除用户
function exportReportList(){
if(ROWS_COUNT==0){
	alert("导出的结果集不可以为空！");
	return false;
}

var xmlname = "T_FIXED_ASSETS";

	var url = cw.common.path + '/json?action=QUERY_T_FIXED_ASSETSBY_PAGER_FOR_REPORT_ACTION';
	url += "&CREATE_DATE_BEGIN="+$('#CREATE_DATE_BEGIN').val()
		+"&CREATE_DATE_END="+$('#CREATE_DATE_END').val()+"&IS_VALID=1&IS_EXPORT=1";
	
	$.post(url,{},function(data){
		if(data.success){
			location.href = "download.jsp?fileName=week_increased_report.xls&realExportPath="+data.root.T_FIXED_ASSETS.rs;
		} else {
			alert(data.errors.errmsg);
		}
	},'json');
}
//周控制

  function   mm(inputStr)   
  {   
          var   n   =   Date.parse(inputStr.replace(/-/g,   "/"));   
          if(isNaN(n))   {alert("Date   string   is   wrong!");   return;}   
          var   d   =   new   Date(n);   
          //document.getElementById("week1").value   =   d.getWeek();   
          //document.getElementById("week2").value   =   d.getWeek(true);   
          var   fe   =   getFirstAndEnd(d);   
          document.getElementById("CREATE_DATE_BEGIN").value   =   fe.first.format("yyyy-MM-dd");   
          document.getElementById("CREATE_DATE_END").value   =   fe.end.format("yyyy-MM-dd");   
  }     
    
  Date.prototype.getWeek   =   function(flag)   
  {   
      var   first   =   new   Date(this.getFullYear(),   0,   1);   
      var   n   =   parseInt("1065432".charAt(first.getDay()));   
      n   =   this.getTime()-first.getTime()-n*24*60*60*1000;   
      n   =   Math.ceil(n/(7*24*60*60*1000));   
      return   (flag==true&&first.getDay()!=1)?(n+1):n;   
  };   
  Date.prototype.format   =   function(format)   
  {   
      var   o   =   {   
          "M+"   :   this.getMonth()+1,   //month   
          "d+"   :   this.getDate(),         //day   
          "h+"   :   this.getHours(),       //hour   
          "m+"   :   this.getMinutes(),   //minute   
          "s+"   :   this.getSeconds(),   //second   
          "q+"   :   Math.floor((this.getMonth()+3)/3),     //quarter   
          "S"   :   this.getMilliseconds()   //millisecond   
      }   
      if(/(y+)/.test(format))   format=format.replace(RegExp.$1,   
          (this.getFullYear()+"").substr(4   -   RegExp.$1.length));   
      for(var   k   in   o)if(new   RegExp("("+   k   +")").test(format))   
          format   =   format.replace(RegExp.$1,   
              RegExp.$1.length==1   ?   o[k]   :     
                  ("00"+   o[k]).substr((""+   o[k]).length));   
      return   format;   
  };   
    
  function   getFirstAndEnd(d)   
  {   
      var   w   =   d.getDay(),   n   =   24*60*60*1000;   
      var   first   =   new   Date(d.getTime()   -   parseInt("6012345".charAt(w))*n);   
      var   end   =   new   Date(d.getTime()   +   parseInt("0654321".charAt(w))*n);   
      return   {first:   first,   end:   end};   
  }   
